//index.js
//获取应用实例
var utils = require("../../utils/util");
var app = getApp();
var flag = true;
Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    kosamInfo: 'Hello Kosam!',
    customerMessage:""
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    // onLoad  页面初始化 options 为页面跳转所带来的参数
    console.log('onLoad')
    //this 指的就是本页面Page对象
    var that = this
    //调用应用实例的方法获取全局数据
    var newUserInfo;
    var kosamMessage;
    app.getUserInfo(function(userInfo){
      newUserInfo = userInfo;
      //更新本页面
      //that.update()
    })
    kosamMessage = utils.getMessage;
    //更新数据
    that.setData({
      userInfo:userInfo,
      customerMessage:kosamMessage
    })
  },
  onReady: function() {
    console.log('页面初次渲染完成')
  },
  onShow: function() {
    console.log('页面显示')
  },
  onHide: function() {
    console.log('页面隐藏')
  },
  onUnload:function(){
    // 页面关闭
    console.log('页面卸载')
  },
  click_event: function() {
    console.log('点击事件, click_event');
    var new_color = "window";
    if(flag) {
      new_color = "window-red";
      flag = false;
    } else {
      new_color = "window";
      flag = true;
    }
    this.setData({
      color:new_color
    })
  }
})

/*
var flag = true;
Page({
  //data 页面初始化数据
  data: {
    //text: "这是一个页面",
    color: "window"
  },
  click_event: function() {
    console.log('点击事件: myClickEvent');
    var new_color = "window";
    if(flag) {
      new_color = "window-red";
      flag = false;
    } else {
      new_color = "window";
      flag = true;
    }
    this.setData({
      color:new_color
    });
    
  },
  //监听页面加载
  onLoad: function(options) {
    //页面初始化options为页面跳转所带来的参数
    console.log('页面加载')
  },
  //监听页面初次渲染完成
  onReady: function() {
    //页面渲染完成
    console.log('页面初次渲染完成')
  },
  //监听页面显示
  onShow: function() {
    //页面显示时调用
    console.log('页面显示')
  },
  //监听页面隐藏
  onHide: function() {
    //页面隐藏是调用
    console.log('页面隐藏')
  },
  //监听页面卸载
  onUnload:function(){
    // 页面关闭
    console.log('页面卸载')
  }

})
*/
